Android
How to authorise user in background
To authorise user in background you should override AuthenticationProvider
class MyAuthenticationProvider : AuthenticationProvider {
override suspend fun onTokenRequired(reason: Reason): AuthData? {
// do a call to your backend to obtain huma session
}
}
Where AuthData
is a data class that contains the auth token and refresh token.
data class AuthData(
val authToken: String,
val refreshToken: String,
)
Then register this class in SDK initializer
context.installHumaSdk {
sdk {
authKit {
authProvider(MyAuthenticationProvider())
// or
autoInitAuthProvider(MyAuthenticationProvider())
}
}
}
Note: Make sure to close all the activities that are not part of the Huma SDK flow before calling the
start
method.
If AuthenticationProvider
is registered with autoInitAuthProvider
method, SDK will
automatically call onTokenRequired
on the app start.
In on other case, when it's registered with authProvider
method, you should do this call when your
are ready to authorise the user.
HumaAuthKitManager.getInstance().authorize()